#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define     MAX_SIZE    32

unsigned int reverse_bits( unsigned value )
{
    unsigned int reverse_value = 0;//改变后的值
    unsigned int b = 0;//存放临时变量
    int String[33]={0};
    for( int i = 0; i < 31; i++ )
    {
        b = value & 1;          //获取value的最右边的数字 比如： 000101 获取的是 1
        value = value >> 1;     //原值抛掉已经被获取的数字
        reverse_value |= b;     //给目标最右边位已经获取的值，00010 -> 000100 or 00010 -> 000101
        reverse_value <<= 1;    //目标左移,循环结束时已经是32位了

        String[i] = value & 1;
    }
    printf("output:\n二进制为:0");
    for( int i = 0; i < 31; i++ )
    {
        printf("%d",String[i]);
    }
    printf("\n");
    return reverse_value;
}

void ErJinZhi(int i)
{
    int array[MAX_SIZE]={-1};
    int k = 0;
    while( i > 0)
    {
        array[k] = i%2;
        i /= 2;
        k++;
    } 
    for(int i = k; i >= 0; i--)
    {
        printf("%d",array[i]);
    }
    printf("\n");
}


int main()
{
    unsigned int value;
    printf("please input a number\n");
    scanf("%d",&value);
    //while( scanf("%d",&value) != 0 && scanf("%d",&value) != EOF )
    printf("input:\n");
    ErJinZhi(value);
    if( value != 0)
    {
        printf("十进制为:%d\n",reverse_bits(value));
    //    printf("please input a number\n");
    }
    printf("\n");
    return 0;
}
